﻿using System.Collections.Generic;
using Sustainalytics.Entities;
using System.Security.Claims;

namespace Sustainalytics.Claims
{
    public class OperationClaimsRetriever : IOperationClaimsRetriever
    {
        protected IClaimsL1Cache L1Cache { get; set; }

        static OperationClaimsRetriever()
        {
            
        }

        public OperationClaimsRetriever()
            :this(new ClaimsL1Cache())
        {

        }

        public OperationClaimsRetriever(IClaimsL1Cache l1cache)
        {
            this.L1Cache = l1cache;
        }

        public void AddClaims(Entities.Claims claims)
        {
            this.L1Cache.AddClaims(claims);
        }

        public void AddResourceMap(List<ResourceMap> map)
        {
            this.L1Cache.AddResourceMap(map);
        }

        public void AddUserClaims(List<UserClaim> claims)
        {
            this.L1Cache.AddUserClaims(claims);
        }

        public IEnumerable<Claim> GetClaims(Resource resource, string verb, List<ResourceParameters> parameters)
        {
            return this.L1Cache.GetClaims(resource, verb, parameters);
        }

        public IEnumerable<Claim> GetUserClaims(Account acc)
        {
            return this.L1Cache.GetUserClaims(acc.GetNameIdKey());
        }

        public void DeleteResourceMap(ResourceMap map)
        {
            this.L1Cache.DeleteResourceMap(map);
        }

        public void DeleteUserClaims(Account acc, List<Claim> claims)
        {
            this.L1Cache.DeleteUserClaims(acc.GetNameIdKey(), claims);
        }
        public void DeleteUser(Account acc)
        {
            this.L1Cache.DeleteUser(acc.GetNameIdKey());
        }

        public IEnumerable<ResourceMap> GetAllResourceMaps()
        {
            return this.L1Cache.GetAllResourceMaps();
        }

        public IEnumerable<ClaimMap> GetAllClaimMaps()
        {
            return this.L1Cache.GetAllClaimMaps();
        }

        public IEnumerable<Claim> GetPermissionClaims(string permissionName)
        {
            return this.L1Cache.GetPermissionClaims(permissionName);
        }

        public IEnumerable<ResourceMap> GetUIResources(List<Claim> claims)
        {
            return this.L1Cache.GetUIResources(claims);
        }

        #region Privates
    
        #endregion



        public void ClearMemoryCache()
        {
            this.L1Cache.ClearMemoryCache();
        }
    }
}
